package com.seuic.hnjiningposapp.hnapps.ui.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.SPStaticUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.seuic.hnjiningposapp.R;

import butterknife.BindView;

import butterknife.OnClick;


/**
 * 签到页面
 *
 * @author lucifer
 */
public class SingInPopup extends BaseCenterPopupView {

    @BindView(R.id.loging_qd)
    ImageView loging_qd;//签到
    @BindView(R.id.input_accnum_layout)
    LinearLayout input_accnum_layout;//操作员账号--布局
    @BindView(R.id.loging_home_layout)
    LinearLayout loging_home_layout;
    @BindView(R.id.input_accnum_edtext)
    EditText input_accnum_edtext;//操作员账号
    @BindView(R.id.input_accnum_gztext)
    Button input_accnum_gztext;//操作员账号---更正
    @BindView(R.id.input_accnum_oktext)
    Button input_accnum_oktext;//操作员账号---确认

    @BindView(R.id.re_input_namelayout)
    LinearLayout reInputNamelayout;
    @BindView(R.id.input_password_edtext)
    EditText inputPasswordEdtext;//操作员密码
    @BindView(R.id.input_password_gztext)
    Button inputPasswordGztext;//操作员密码--更正
    @BindView(R.id.input_password_oktext)
    Button inputPasswordOktext;//操作员密码--确认
    @BindView(R.id.re_password_namelayout)
    LinearLayout rePasswordNamelayout;
    @BindView(R.id.input_password_layout)
    LinearLayout inputPasswordLayout;//操作员密码--布局
    @BindView(R.id.singin_layout)
    LinearLayout singinLayout;
    private String account;

    private OnSingInListener onSingInListener;


    /**
     * 签到页面回调事件
     */
    public interface OnSingInListener {
        /**
         * 回调方法
         *
         * @param account 账号
         * @param pwd     密码
         */
        void singIn(String account, String pwd);
    }

    public void setOnSingInListener(OnSingInListener onSingInListener) {
        this.onSingInListener = onSingInListener;
    }

    Activity mActivity;

    public SingInPopup(@NonNull Context context, Activity activity) {
        super(context);
        this.mActivity = activity;
    }

    @Override
    protected void onCreate() {
        super.onCreate();

    }

    @Override
    protected int getImplLayoutId() {
        return R.layout.dialog_singin;
    }


    @OnClick({R.id.loging_qd, R.id.input_accnum_gztext, R.id.input_accnum_oktext, R.id.input_password_gztext
            , R.id.input_password_oktext})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.loging_qd:
                //隐藏签到
                loging_home_layout.setVisibility(GONE);
                //显示输入管理员账号
                input_accnum_layout.setVisibility(VISIBLE);
                break;
            case R.id.input_accnum_gztext:
                //输入账号更正
                input_accnum_edtext.setText("");
                break;
            case R.id.input_accnum_oktext:
                //输入账号确定
                account = input_accnum_edtext.getText().toString().trim();
                if (TextUtils.isEmpty(account)) {
                    ToastUtils.showLong("请输入操作员账号");
                } else {
                    //隐藏输入操作员账号布局
                    input_accnum_layout.setVisibility(View.GONE);
                    //显示输入操作员密码布局
                    inputPasswordLayout.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.input_password_gztext:
                //输入密码更正
                inputPasswordEdtext.setText("");
                break;
            case R.id.input_password_oktext:
                //输入密码确定
                String pwd = inputPasswordEdtext.getText().toString().trim();
                if (TextUtils.isEmpty(pwd)) {
                    ToastUtils.showLong("请输入账户密码");
                } else {
                    inputPasswordLayout.setVisibility(View.GONE);
                    singinLayout.setVisibility(View.VISIBLE);
                    if (onSingInListener != null) {
                        onSingInListener.singIn(account, pwd);
                    }
                }
                break;
            default:
                break;
        }
    }

    public void recover() {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                singinLayout.setVisibility(View.GONE);
                inputPasswordLayout.setVisibility(View.GONE);
                input_accnum_layout.setVisibility(VISIBLE);
            }
        });

    }


}